﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.IDAL;
using KPIS.GERP.GFMS.DALFactory;

// test only
using KPIS.GERP.GFMS.DAL;

namespace KPIS.GERP.GFMS.BLL
{
    [Serializable]
    public class B_HRM_PR_PayrollDtls : IBLL_HRM_PR_PayrollDtls
    {
        Common common = new Common();
        private static readonly IDAL_HRM_PR_PayrollDtls dal = DataAccess.Create_HRM_PR_PayrollDtls();
        //IBLL_HRM_PR_PayrollDtls r = new B_HRM_PR_PayrollDtls();

        public B_HRM_PR_PayrollDtls()
        {

        }

        public IList<M_HRM_PR_PayrollDtls> GetSummary(string emp_type_seq
            , string job_site_gfmis, string pay_year, string pay_month)
        {
            Nullable<int> nemp_type_seq = common.ConvertNullInt(emp_type_seq);
            Nullable<int> njob_site_gfmis = common.ConvertNullInt(job_site_gfmis);
            Nullable<int> npay_year = common.ConvertNullInt(pay_year);
            Nullable<int> npay_month = common.ConvertNullInt(pay_month);
            return dal.GetSummary(nemp_type_seq, njob_site_gfmis, npay_year, npay_month);
        }

        public IList<M_HRM_PR_PayrollDtls> GetFull(string emp_seq, string ext_flag, string pay_seq)
        {
            Nullable<int> nemp_seq = common.ConvertNullInt(emp_seq);
            Nullable<int> npay_seq = common.ConvertNullInt(pay_seq);
            return dal.GetFull(nemp_seq, ext_flag, npay_seq);
        }

        public IList<M_HRM_PR_PayrollDtls> GetSummaryByJobsiteGFMIS(string pay_seq, string ext_seq, string job_site_gfmis)
        {
            Nullable<int> npay_seq = common.ConvertNullInt(pay_seq);
            Nullable<int> next_seq = common.ConvertNullInt(ext_seq);
            return dal.GetSummaryByJobsiteGFMIS(npay_seq, next_seq, job_site_gfmis);
        }

        public IList<M_HRM_PR_PayrollDtls> GetFullFromMoneyReqSeq(string money_req_seq)
        {
            Nullable<int> nmoney_req_seq = common.ConvertNullInt(money_req_seq);
            return dal.GetFullFromMoneyReqSeq(nmoney_req_seq);
        }

        public M_HRM_PR_PayrollDtls GetInfo(string seq)
        {
            int nSeq;
 
            if (seq == null)
                return null;

            if (common.IsNumeric(seq))
            {
                nSeq = int.Parse(seq);
                return dal.GetInfo(nSeq);
            }
            else
            {
                return null;
            }
        }

        public string GetPaySeq(string emp_type_seq, string pay_year, string pay_month)
        {
            Nullable<int> nemp_type_seq = common.ConvertNullInt(emp_type_seq);
            Nullable<int> npay_year = common.ConvertNullInt(pay_year);
            Nullable<int> npay_month = common.ConvertNullInt(pay_month);

            return dal.GetPaySeq(nemp_type_seq, npay_year, npay_month);
        }

        public void Insert(M_HRM_PR_PayrollDtls info)
        {
            try
            {
                dal.Insert(info);
            }
            catch
            {
                throw;
            }
        }

        public void Update(M_HRM_PR_PayrollDtls info)
        {
            try
            {
                dal.Update(info);
            }
            catch
            {
                throw;
            }
        }

        public void Delete(M_HRM_PR_PayrollDtls info)
        {
            try
            {
                dal.Delete(info);
            }
            catch
            {
                throw;
            }
        }

        public void UpdateMoneyReqDtlsSeq(string pay_seq, string job_site_seq
            , string money_req_dtls_seq, string emp_seq)
        {
            try
            {
                Nullable<int> npay_seq = common.ConvertNullInt(pay_seq);
                Nullable<int> njob_site_seq = common.ConvertNullInt(job_site_seq);
                Nullable<int> nmoney_req_dtls_seq = common.ConvertNullInt(money_req_dtls_seq);
                Nullable<int> nemp_seq = common.ConvertNullInt(emp_seq);
                dal.UpdateMoneyReqDtlsSeq(npay_seq, njob_site_seq, nmoney_req_dtls_seq, nemp_seq);
            }
            catch
            {
                throw;
            }
        }

        public void ClearMoneyReqDtlsSeq(string pay_seq, string job_site_seq
            , string money_req_dtls_seq, string emp_seq)
        {
            try
            {
                Nullable<int> npay_seq = common.ConvertNullInt(pay_seq);
                Nullable<int> njob_site_seq = common.ConvertNullInt(job_site_seq);
                Nullable<int> nmoney_req_dtls_seq = common.ConvertNullInt(money_req_dtls_seq);
                Nullable<int> nemp_seq = common.ConvertNullInt(emp_seq);
                dal.UpdateMoneyReqDtlsSeq(npay_seq, njob_site_seq, nmoney_req_dtls_seq, nemp_seq);
            }
            catch
            {
                throw;
            }
        }
    }
}
